package com.prg.action.app.login;



import com.prg.action.app.BaseController;
import com.prg.model.base.AuthUser;
import com.prg.model.easyui.Json;
import com.prg.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import com.prg.util.JsonUtil;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Created with IntelliJ IDEA.
 * User: Administrator
 * Date: 14-12-4
 * Time: 下午9:03
 * To change this template use File | Settings | File Templates.
 */
@Controller
@RequestMapping("/login")
public class LoginController extends BaseController{
    @Autowired
    UserService userService;

    @RequestMapping(value = "/logintest" ,method = RequestMethod.POST)
    public void logintest(AuthUser user,HttpServletRequest request,HttpServletResponse response){
        Json json=new Json();

        if(null!=user){
           if(userService.testUser(user)){
               json.setMsg("登录成功");
               json.setSuccess(true);
               json.setObj(user);
           }
        }else {
            json.setMsg("密码不正确!");
        }
        JsonUtil.writeJson(response,json);
    }
    @RequestMapping(value = "/adduser",method = RequestMethod.POST)
    public void addUser(AuthUser user,HttpServletRequest request,HttpServletResponse response){
        Json json=new Json();

        if(null!=user){
            if(userService.saveAddUser(user)){
                json.setMsg("用户添加成功");
                json.setSuccess(true);
                json.setObj(user);
            }
        }else {
            json.setMsg("用户添加失败!");
        }
        JsonUtil.writeJson(response,json);
    }
}
